package tk1.uebung3.restful;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import tk1.uebung3.model.Assortment;
import tk1.uebung3.model.ProductType;

@Path("/availability/{productName}")
public class Availability {
	
	@GET
	@Produces(MediaType.TEXT_PLAIN)
	public String getAvailability(@PathParam("productName") String productName) {
		Assortment assortment = Assortment.getInstance();
		ProductType productType = assortment.getProductTypeByName(productName);
		String response;
		if(productType != null){
			response = String.valueOf(productType.getAvailableAmount());
		}
		else{
			response = "availability not found";
		}
		return response;
	}
	


}
